package neichuan;

import neichuan.center.RegistCenter;
import neichuan.server.message.RegisterServer;
import neichuan.util.log.Log;
import org.apache.log4j.Logger;

public class WorkSpace {

    private static WorkSpace workSpace;
    RegistCenter registCenter=new RegistCenter();
    RegisterServer registerServer;
    Thread registerServerThread;
    private WorkSpace(){ }
    public static WorkSpace getSingleInstance(){
        if(workSpace==null){
            synchronized (WorkSpace.class){
                if(workSpace==null){
                    workSpace=new WorkSpace();
                }
            }
        }
        return workSpace;
    }


    public RegistCenter getRegistCenter(){
        return registCenter;
    }

    public void start(int port){
        registerServer=new RegisterServer(port);
        registerServerThread=new Thread(registerServer);
        registerServerThread.start();
    }

    public void close(){
        registerServer.close();
        registCenter.close();
        Log.info("服务器关闭");
    }



}
